/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package damei;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author Administrator
 */
 public class UserMouseAdapter
    extends java.awt.event.MouseAdapter {
    private Statement stmt1;
    private Statement stmt;
    private String driver;
    private String url;
    private String user;
    private String password;

        public UserMouseAdapter() {
        }

        
         private boolean flag=false;//用来判断是否已经执行双击事件
  private int clickNum=0;//用来判断是否该执行双击事件

  public void mouseClicked(MouseEvent e) {
      final MouseEvent me=e;//事件源

      this.flag=false;//每次点击鼠标初始化双击事件执行标志为false

      if (this.clickNum == 1) {//当clickNum==1时执行双击事件
        this.mouseDoubleClicked(me);//执行双击事件
        this.clickNum=0;//初始化双击事件执行标志为0
        this.flag=true;//双击事件已执行,事件标志为true
        return;
      }
       
       

       //定义定时器
      java.util.Timer timer=new java.util.Timer();

      //定时器开始执行,延时0.2秒后确定是否执行单击事件
      timer.schedule(new java.util.TimerTask(){
        private int n=0;//记录定时器执行次数
        public void run() {
          if(flag){//如果双击事件已经执行,那么直接取消单击执行
            n=0;
            clickNum=0;
            this.cancel();
            return;
          }
          if (n == 1) {//定时器等待0.2秒后,双击事件仍未发生,执行单击事件


            mouseSingleClicked(me);//执行单击事件
            flag = true;
            clickNum=0;
            n=0;
            this.cancel();
            return;
          }
          clickNum++;
          n++;
        }
      },new java.util.Date(),300); // 设置延迟时间
    }
        
         public void mouseSingleClicked(MouseEvent e){
      //System.out.println("Single Clicked!");
    } 

    /** *//**
     * 鼠标双击事件
     * @param e 事件源参数
     */
    public void mouseDoubleClicked(MouseEvent e){
      //System.out.println("Doublc Clicked!");
       
    }

    public void showClick(Object o) {
       String s=o.toString();
       usershow();
    
 try
  {
 driver ="com.mysql.jdbc.Driver";
 url    ="jdbc:mysql://192.168.1.250:3306/damei";
 user   ="root";
 password="root";
  Connection con=DriverManager.getConnection(url,user,password);
  if(!con.isClosed())
  System.out.println("打开数据库成功");
 
  
  //根据名字来查询资料
  
  stmt = con.createStatement();
  String searchnameu="select * from user where name='"+s+"';";
   ResultSet rsuser=stmt.executeQuery(searchnameu);
    while (rsuser.next()) {
           
    //System.out.print( rsuser.getObject(3));
    Main.jno.setText(rsuser.getObject(2).toString());
    Main.jname.setText(rsuser.getObject(3).toString());
    Main.jsex.setSelectedItem(rsuser.getObject(4));
    Main.jjg.setText(rsuser.getObject(5).toString());
    Main.jphone.setText(rsuser.getObject(6).toString());
    Main.jcphone.setText(rsuser.getObject(7).toString());
    Main.qq.setText(rsuser.getObject(8).toString());
    Main.jsfz.setText(rsuser.getString(9)); 
    Main.jemail.setText(rsuser.getObject(10).toString());
    Main.jmz.setText(rsuser.getString(11));
    Main.jbd.setText(rsuser.getObject(12).toString());
    Main.jhy.setSelectedItem(rsuser.getObject(13));
    Main.jyb.setText(rsuser.getObject(14).toString());
    Main.jwb.setText(rsuser.getObject(15).toString());
    Main.jyjr.setText(rsuser.getObject(16).toString());
    Main.jyjp.setText(rsuser.getObject(17).toString());
    Main.jyjd.setText(rsuser.getObject(18).toString());
    Main.jwork.setText(rsuser.getObject(19).toString());
    Main.jaddr.setText(rsuser.getString(20));
    Main.jwaddr.setText(rsuser.getObject(21).toString());
    Main.jzx.setText(rsuser.getObject(22).toString());
    Main.jzr.setText(rsuser.getObject(23).toString());
    Main.jzsh.setText(rsuser.getObject(24).toString());
    Main.jjbr.setText(rsuser.getObject(25).toString());
    Main.jjbrq.setText(rsuser.getObject(26).toString());
    Main.jother.setText(rsuser.getObject(27).toString());
    
 }
 
   
  stmt1 = con.createStatement();
    String searchnamed="select * from driver where name='"+s+"';";
     ResultSet rsdriver=stmt1.executeQuery(searchnamed);
 
    while (rsdriver.next()) {
        Main.brand.setText(rsdriver.getObject(5).toString());
        Main.cartype.setText(rsdriver.getObject(6).toString());
        Main.jszh.setText(rsdriver.getObject(7).toString());
        Main.gcrq.setText(rsdriver.getObject(8).toString());
        Main.lzrq.setText(rsdriver.getObject(9).toString());
        Main.pl.setText(rsdriver.getObject(10).toString());
        Main.dw.setSelectedItem(rsdriver.getObject(11));
        Main.cphm.setText(rsdriver.getObject(12).toString());
        Main.jl.setText(rsdriver.getObject(13).toString());
        Main.xsz.setText(rsdriver.getObject(14).toString());
        Main.tbgs.setText(rsdriver.getString(15));
        Main.tbrq.setText(rsdriver.getString(16));
 }
    System.out.println("查询成功");
  
  stmt.close();
  stmt1.close();
  con.close();
  }
   catch(Exception e){
            System.out.print("Error occurred in inserting data");
            e.printStackTrace();
        }
    }

     
    /**
     *
     */
     
      
     private void usershow() {
     Main.users.setVisible(true);
     Main.jf.setVisible(false);
     Main.yw.setVisible(false); 
     Main. other.setVisible(false);
     Main. main.setVisible(false);
     Main.editbutton.enableInputMethods(true);
    } 

    }
